﻿using System.Web.Mvc;
using System.Web.Mvc.Html;
using CodeContrib.Web.Routing;

namespace CodeContrib.Web.Mvc.Html
{
	public static class ActionLinkExtensions
	{
		public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues)
		{
			return htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, null);
		}

		public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string actionName)
		{
			return ActionLink(htmlHelper, innerHtml, actionName, null, null, null, null, null, null);
		}

		public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string actionName, string controllerName)
		{
			return ActionLink(htmlHelper, innerHtml, actionName, controllerName, null, null, null, null, null);
		}

		public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string actionName, object routeValues)
		{
			return ActionLink(htmlHelper, innerHtml, actionName, null, null, null, null, routeValues, null);
		}

		public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string actionName, string controllerName, object routeValues)
		{
			return ActionLink(htmlHelper, innerHtml, actionName, controllerName, null, null, null, routeValues, null);
		}

		public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string actionName, object routeValues, object htmlAttributes)
		{
			return ActionLink(htmlHelper, innerHtml, actionName, null, null, null, null, routeValues, htmlAttributes);
		}

		public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string actionName, string controllerName, object routeValues, object htmlAttributes)
		{
			return ActionLink(htmlHelper, innerHtml, actionName, controllerName, null, null, null, routeValues, htmlAttributes);
		}

		public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string actionName, string controllerName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes)
		{
			var url = UrlHelper.GenerateUrl(null, actionName, controllerName, protocol, hostName, fragment, routeValues.ToRouteValueDictionary(), htmlHelper.RouteCollection, htmlHelper.ViewContext.RequestContext, false /* includeImplicitMvcValues */);

			return htmlHelper.Link(innerHtml, url, htmlAttributes);
		}
	}
}